//
//  MyselfHeaderView.m
//  LiuHeBao
//
//  Created by zr on 2018/8/22.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "MyselfHeaderView.h"

@interface MyselfHeaderView ()

@property(nonatomic, weak)UIImageView * iconImageView;
@property(nonatomic, weak)UILabel * nameLabel;
@property(nonatomic, weak)UILabel * subLabel;
@property(nonatomic, strong)UIButton * infoButton;
@property(nonatomic, strong)UIButton * myWishButton;
@property(nonatomic, strong)UIButton * myCommitButton;
@property(nonatomic, strong)UIButton * myCollectionButton;
@property(nonatomic, weak)UIView * lineView;


@end

@implementation MyselfHeaderView

- (void)setName:(NSString *)name{
    
    _name = name;
    
    self.nameLabel.text = name;
}

- (void)setImageUrl:(NSURL *)imageUrl{
    
    _imageUrl = imageUrl;
    
    [self.iconImageView sd_setImageWithURL:imageUrl placeholderImage:ImageNamed(@"weidenglu")];
}


-  (void)setExperson:(NSString *)experson{
    
    _experson = experson;
    
    self.subLabel.text = experson;
}


- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    
    self.backgroundColor = [UIColor whiteColor];

    UIImageView * iconImageView = [UIImageView new];
    
    //  把图片设置成圆形
    iconImageView.layer.cornerRadius = 25;//裁成圆角
    iconImageView.layer.masksToBounds = YES;//隐藏裁剪掉的部分
    
    iconImageView.image = ImageNamed(@"weidenglu");
    //    iconImageView.backgroundColor = [UIColor redColor];
    
    self.iconImageView = iconImageView;
    
    [self addSubview:self.iconImageView];
    
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.text = @"用户姓名";
    nameLabel.textColor = BLACK_COLOR;
    nameLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.nameLabel = nameLabel;
    
    [self addSubview:self.nameLabel];
    
    
    UILabel * subLabel = [UILabel new];
    
    subLabel.text = @"这个家伙很懒什么都没留下";
    subLabel.textColor = [UIColor lightGrayColor];
    subLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.subLabel = subLabel;
    
    [self addSubview:self.subLabel];
    
    
    self.infoButton = [self setupButtonWithImage:@"sadas203"];
    [self addSubview:self.infoButton];
    self.myWishButton = [self setupButtonWithImage:@"sadas1"];
    [self addSubview:self.myWishButton];
    self.myCommitButton = [self setupButtonWithImage:@"pinglun"];
    [self addSubview:self.myCommitButton];
    self.myCollectionButton = [self setupButtonWithImage:@"dsfsd30"];
    [self addSubview:self.myCollectionButton];
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0x909090);
    
    self.lineView = lineView;
    
    [self addSubview:self.lineView];
}


- (void)layoutSubviews{
    
    CGFloat width = SCREEN_WIDTH / 4;

    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(20 * SCREENH6);
        make.leading.mas_equalTo(self).offset(10 * SCREENH6);
        make.height.width.mas_equalTo(50 * SCREENH6);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(15 * SCREENH6);
        make.centerY.mas_equalTo(self.iconImageView).offset(-10 * SCREENH6);
    }];
    
    [self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(6 * SCREENH6);
    }];
    
    [self.infoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self);
        make.top.mas_equalTo(self.iconImageView.mas_bottom).offset(5 * SCREENH6);
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(49 * SCREENH6);
    }];
    
    [self.myWishButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.infoButton.mas_trailing);
        make.centerY.width.height.mas_equalTo(self.infoButton);
    }];
    
    [self.myCommitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.myWishButton.mas_trailing);
        make.centerY.width.height.mas_equalTo(self.myWishButton);
    }];
    
    [self.myCollectionButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.myCommitButton.mas_trailing);
        make.centerY.width.height.mas_equalTo(self.myCommitButton);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self);
        make.height.mas_equalTo(3 * SCREENH6);
    }];
}


- (UILabel *)setupLabelWith:(NSString *)string{
    
    UILabel * label = [UILabel new];
    
    label.text = string;
    label.textColor = BLACK_COLOR;
    label.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    
    return label;
}

//
- (UIButton *)setupButtonWithImage:(NSString *)str{
    
    UIButton * button = [UIButton new];
    
    [button setImage:ImageNamed(str) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickFourButton:) forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}

- (UIView *)setupLineView{
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0x909090);
    
    
    return lineView;
}


- (void)clickFourButton:(UIButton *)button{
    
    NSString * type;
    
    if (button == self.infoButton) {
        
        type = @"info";
    }else if (button == self.myWishButton){
        
        type = @"wish";
    }else if (button == self.myCommitButton){
        
        type = @"commit";
    }else if (button == self.myCollectionButton){
        
        type = @"collection";
    }
    
    NSDictionary * dict = @{@"type":type};
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"clickMyselfHeaderView" object:nil userInfo:dict];
}

@end
